package com.atguigu.dga.governance.service.impl;

import com.atguigu.dga.governance.service.*;
import com.atguigu.dga.meta.service.TableMetaInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

/**
 * ClassName: MainGovernanceAssessImpl
 * Package: com.atguigu.dga.governance.service.impl
 * Description:
 *
 * @Author: tubage
 * @Create: 2024/3/23 09:06
 * @Version: 1.0
 */
@Service
public class MainGovernanceAssessImpl implements MainGovernanceService {
    @Autowired
    private TableMetaInfoService tableMetaInfoService;
    @Autowired
    private GovernanceAssessDetailService governanceAssessDetailService;
    @Autowired
    private GovernanceAssessTableService governanceAssessTableService;
    @Autowired
    private GovernanceAssessTecOwnerService governanceAssessTecOwnerService;
    @Autowired
    private GovernanceAssessGlobalService governanceAssessGlobalService;
    @Value("${default.datawarehouse.database}")
    private String defaultSchemaName;

    // TODO 定时调度 待补充
    @Scheduled(cron = "10 15 14 * * *") // 每一天某个时间调度
    public void startAssess() throws Exception {
       String assessDate = "2023-05-02"; // 正常就获取当前日期
       startAssess(defaultSchemaName, assessDate);
    }

    // TODO 串联
    @Override
    public void startAssess(String schemaName, String assessDate) throws Exception {
        // TODO 1 提取元数据
        tableMetaInfoService.initTableMetaInfo(schemaName,assessDate);
        // TODO 2 考评
        governanceAssessDetailService.mainAssess(assessDate);
        // TODO 3 分数
        governanceAssessTableService.calcTableScore(assessDate);
        governanceAssessTecOwnerService.calcTecOwnerScore(assessDate);
        governanceAssessGlobalService.calcGlobalScore(assessDate);
    }

    // TODO 前端页面接口 重载方法
    public void startAssess(String assessDate) throws Exception {
        startAssess(defaultSchemaName, assessDate);
    }
}
